package com.yinhe.module.gs.disciplinary.controller;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.domain.entity.SysUser;
import com.yinhe.common.core.domain.model.LoginUser;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.DateUtils;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhContent;
import com.yinhe.system.service.IYhContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 内容公告发布Controller
 * 
 * @author yinhe
 * @date 2022-07-14
 */
@RestController
@RequestMapping("/gs/disciplinary")
public class YhDisciplinaryController extends BaseController
{
    @Autowired
    private IYhContentService yhContentService;

    /**
     * 查询内容公告发布列表
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhContent yhContent)
    {
        startPage();
        List<YhContent> list = yhContentService.selectYhContentList(yhContent);
        return getDataTable(list);
    }

    /**
     * 导出内容公告发布列表
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:export')")
    @Log(title = "内容公告发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhContent yhContent)
    {
        List<YhContent> list = yhContentService.selectYhContentList(yhContent);
        ExcelUtil<YhContent> util = new ExcelUtil<YhContent>(YhContent.class);
        util.hideColumn("noticeType","pictureUrl","sourcesUrl","participants","viewsTimes","haveExperience",
                "experienceContent","fileNum","userId","deptId","noticeId","documentNo",
                "implementationTime","security","yearsLimit","note2","note1",
                "note3","note4","note5","note6","note7","note8","note9","note10"
        );
        util.exportExcel(response, list, "纪检监察发布数据");
    }

    /**
     * 获取内容公告发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhContentService.selectYhContentById(id));
    }

    /**
     * 新增内容公告发布
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:add')")
    @Log(title = "内容公告发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhContent yhContent)
    {// 获取当前登录用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getUser();
        // 存入userId和deptId，做数据权限
        yhContent.setUserId(sysUser.getUserId());
        yhContent.setDeptId(sysUser.getDeptId());
        yhContent.setReleaseTime(DateUtils.getNowDate());
        return toAjax(yhContentService.insertYhContent(yhContent));
    }

    /**
     * 修改内容公告发布
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:edit')")
    @Log(title = "内容公告发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhContent yhContent)
    {
        return toAjax(yhContentService.updateYhContent(yhContent));
    }

    /**
     * 删除内容公告发布
     */
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:remove')")
    @Log(title = "内容公告发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhContentService.deleteYhContentByIds(ids));
    }


/*
    *//**
     * 查询内容公告发布列表
     *//*
    @PreAuthorize("@ss.hasPermi('gs:disciplinary:list')")
    @GetMapping("/listX")
    public TableDataInfo listX(YhContent yhContent )
    {
        startPage();


        List<YhContent> list = yhContentService.selectYhContentList(yhContent);
        return getDataTable(list);
    }*/



}
